<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>axios</title>
    <script src="js/axios.min.js"></script>
  </head>

  <body>
    <script>
      var axios = axios.create();
      axios.interceptors.request.use((config) => {
        console.log("在发送请求前拦截...");
        console.log(config);
        return config;
      });
      axios.interceptors.response.use((res) => {
        console.log("在收到响应后拦截...");
        console.log(res);
        return res;
      });

      axios.defaults.baseURL = "http://localhost:8080";
      axios.get("/index").then(function (result) {
        console.log("response:1");
        console.log(result);
        console.log(result.data);
      });

      axios
        .get("/details", {
          params: {
            lid: 5,
          },
        })
        .then(function (result) {
          console.log("response:2");
          console.log(result);
          console.log(result.data);
        });

      //3.post
      axios
        .post("/user/login", {
          uname: "dingding",
          upwd: 123456,
        })
        .then((response) => {
          console.log("response:3");
          console.log(response);
          console.log(response.data);
        });
    </script>
  </body>
</html>
